﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Windows.Forms;
using SysContext;
using Business_Logic_Layer;

namespace Money_Dance
{
    public partial class UserControlTrangchu : UserControl
    {
        public static int UserID;    
        BUSS BUS = new BUSS();

        public UserControlTrangchu()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Constructor UserControlTrangchu
        /// </summary>
        /// <param name="id"></param>
        public UserControlTrangchu(int id)
        {
            UserID = id;
        }

        private void UserControlTrangchu_Load(object sender, EventArgs e)
        {
            double? Balance = 0;
            Balance = BUS.Balance(UserID, "Checking");
            this.laberChecking.Text = BUS.Balance(UserID, "Checking").ToString();
            this.laberSaving.Text = BUS.Balance(UserID, "Saving").ToString();

            // Lấy lịch nhắc nhở và highlight những giao dịch sẽ được thực tiếp trong 2 ngày tiếp theo.
            Array listReminder= BUS.GetReminder(UserID);
            for (int i = 0; i < listReminder.Length; i++)
            {
                dataGridView_Reminder.Rows.Add();
                dataGridView_Reminder.Rows[i].Cells[Thoigian.Name].Value = ((DateTime)(listReminder.GetValue(i).GetType().GetProperty("StartDate").GetValue(listReminder.GetValue(i), null))).ToShortDateString();
                dataGridView_Reminder.Rows[i].Cells[mota.Name].Value = listReminder.GetValue(i).GetType().GetProperty("Description").GetValue(listReminder.GetValue(i), null);
                dataGridView_Reminder.Rows[i].Cells[sotien.Name].Value = listReminder.GetValue(i).GetType().GetProperty("Balan").GetValue(listReminder.GetValue(i), null);

                DateTime reminderStartDate = DateTime.Parse(dataGridView_Reminder.Rows[i].Cells[0].Value.ToString());
                System.DateTime reminderDate = DateTime.Today.AddDays(2);
                if (DateTime.Compare(reminderDate, reminderStartDate) == 0)
                {
                    dataGridView_Reminder.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                }                
            }
        }                
    }
}
